package com.lk.api.app;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by lk on 2014/12/25.
 */
public class DBOpenHelper extends SQLiteOpenHelper   {


    public DBOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        //    创建表sql语句
        String sqlite = "create TABLE users(_id INTEGER PRIMARY KEY AUTOINCREMENT,names VARCHAR(50),pwd VARCHAR(50));";
        db.execSQL(sqlite);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

        if (oldVersion==1&&newVersion==2){
            //如果从1版本升级
//            db.execSQL("create TABLE usersNew(_id INTEGER PRIMARY KEY AUTOINCREMENT,names VARCHAR(50),pwd VARCHAR(50));");

        }else if(newVersion==2&&oldVersion==1){
            //如果从2版本回滚到1版
//            db.execSQL("drop TABLE usersNew");
        }

    }




}
